/// @description Insert description here
// You can write your code in this editor
var dx,dy,tmp,psp,pdir;
dx=0;
dy=0;
psp=1;
if(state==3)
{
	dead_timer-=1;
	if(dead_timer<=0)game_restart();
	exit;
}
//***按键控制

if(keyboard_check(ord("W")))
{
	dy=-1;
}
if(keyboard_check(ord("S")))
{
	dy=1;	
}
if(keyboard_check(ord("A")))
{
	dx=-1;	
}
if(keyboard_check(ord("D")))
{
	dx=1;	
}
//***保存当前方向
if(dx!=0||dy!=0)
{
	dx2=dx;
	dy2=dy;
}
//求方向
pdir=point_direction(0,0,dx2,dy2);//判断（0，0）到（dx，dy）连线的角度
face=pdir/45;
//***发射子弹
if(keyboard_check(ord("J"))&&shoot_timer<=0)
{
	shoot_timer=30;
	tmp=instance_create_depth(x,y,1,obj_bullet);
	tmp.direction=pdir;
	tmp.image_index=face;
	audio_play_sound(snd_shoot,0,false)
	switch(face)
	{
		case 0:	tmp.x=x+32;tmp.y=y+15;break;
		case 1:	tmp.x=x+30;tmp.y=y+13;break;
		case 2:	tmp.x=x+27;tmp.y=y+11;break;
		case 3:	tmp.x=x+5;tmp.y=y+13;break;
		case 4:	tmp.x=x+4;tmp.y=y+15;break;
		case 5:	tmp.x=x+5;tmp.y=y+21;break;
		case 6:	tmp.x=x+27;tmp.y=y+23;break;
		case 7:	tmp.x=x+30;tmp.y=y+21;break;
	}
	 
}
//***丢雷
if(keyboard_check(ord("K"))&&shoot_timer2<=0)
{
	shoot_timer2=50;
	tmp=instance_create_depth(x+18,y+19,1,obj_lei);
	tmp.direction=pdir+45;
	tmp.gravity_direction=pdir-90;
	if(face==3||face==4||face==5)
	{
		tmp.direction=pdir-45
		tmp.gravity_direction=pdir+90;
	}
	audio_play_sound(snd_reng,0,false);
}
//***计时器自减
shoot_timer-=1;
shoot_timer2-=1;
//***碰撞检测
//**横向检测
tmp=collision_point(x+17+dx*psp,y+29,obj_tree,0,0);
if(tmp)dx=0;
//**纵向检测
tmp=collision_point(x+17,y+29+dy*psp,obj_tree,0,0);
if(tmp)dy=0;
//***边界限制
if((x+xo)<48)x=48-xo;
if((x+xo)>room_width-48)x=room_width-48-xo;
if((y+yo)>room_height)y=room_height-yo;
if(y<0)y=0;

//***坐标移动
x+=dx*psp;
y+=dy*psp;


//***动画变化

tmp=(dx==0&&dy==0);//如果静止则tmp=1
if(tmp)
{
	
	if(image_index_player<3.9)image_index_player+=0.1;
	else image_index_player=0;
	image_index=image_index_player;
	switch(face)
	{
		case 0:sprite_index=spr_player_stand0;break;
		case 1:sprite_index=spr_player_stand1;break;
		case 2:sprite_index=spr_player_stand2;break;
		case 3:sprite_index=spr_player_stand3;break;
		case 4:sprite_index=spr_player_stand4;break;
		case 5:sprite_index=spr_player_stand5;break;
		case 6:sprite_index=spr_player_stand6;break;
		case 7:sprite_index=spr_player_stand7;break;
	}
}
if(!tmp)
{
	if((image_index_player mod 2)==0)audio_play_sound(snd_walk,0,false);
	if(image_index_player<3.9)image_index_player+=0.1;
	else image_index_player=0;
	image_index=image_index_player;
	switch(face)
	{
		case 0:sprite_index=spr_player_walk0;break;
		case 1:sprite_index=spr_player_walk1;break;
		case 2:sprite_index=spr_player_walk2;break;
		case 3:sprite_index=spr_player_walk3;break;
		case 4:sprite_index=spr_player_walk4;break;
		case 5:sprite_index=spr_player_walk5;break;
		case 6:sprite_index=spr_player_walk6;break;
		case 7:sprite_index=spr_player_walk7;break;
	}
}











